package com.seo;

public class calendar {

	public final int[] LEAP = {31,29,31,30,31,30,31,31,30,31,30,31};
	public final int[] NOTLEAP = {31,28,31,30,31,30,31,31,30,31,30,31};
	
	public boolean isLeapYear(int year){
		boolean isS = false;
		if(year%4==0 && year%100!=0 ||year%400==0){
			isS = true;
		}
		return isS;
	}
	
	public int days(int year){
		int tot = 0;
		for (int i = 1; i < year; i++) {
			if(isLeapYear(i)){
				tot += 366;
			}
			else{
				tot += 365;
			}
		}
		return tot;
	}
	
	public int days(int year, int month){
		int tot= days(year);
		for (int i = 1; i < month; i++) {
			if(isLeapYear(i)){
				tot += LEAP[i-1];
			}
			else
			{
				tot += NOTLEAP[i-1];
			}
		}
		return tot;
	}
	
	public int days(int year, int month, int day){
		return days(year,month)+day;
	}
	
	public int lastDay(int year, int month){
		return isLeapYear(year)?LEAP[month-1]:NOTLEAP[month-1];
	}
	
	public void print(int year, int month){
		System.out.printf("                %d년%d월\n", year, month);
		System.out.println("일\t월\t화\t수\t목\t금\t토\t");
		int dayofweek = 1+days(year, month, 1)%7-1;
		
		for (int i =check(year,month)-dayofweek+1; i <= check(year, month); i++) {
			System.out.print(i+"\t");
		}
		
		for (int i = 1; i <= lastDay(year, month); i++) {
			System.out.print(i+"\t");
			if((i+dayofweek)%7==0){
				System.out.println();
			}
		}
		for (int i = 1; i <= dayOfEnd(dayofweek,lastDay(year, month)); i++) 
		{
			System.out.print(i+"\t");
			
		}
		System.out.println();
	} 
	
	public int dayOfEnd(int dayOfWeek, int lastDay)
	{
		int dayOfEnd = 7-((dayOfWeek+lastDay)%7);
		
		return dayOfEnd==7?0:dayOfEnd;
	}
	
	public void calprint(int year){
		for (int i = 1; i < 13; i++) {
			print(year, i);
		}
	}
	
	public int check(int year, int month){
		
		int lastmonth =0;
		if(month ==1)
		{
			lastmonth = lastDay(year-1, month=12);
		}
		else{
			lastmonth = lastDay(year, month-1);
		}
		return lastmonth;
	}
	
}
